package cn.iocoder.yudao.module.fengdong.smartelderly.controller.app.complaint;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.fengdong.smartelderly.controller.admin.complaint.vo.*;
import cn.iocoder.yudao.module.fengdong.smartelderly.convert.complaint.ComplaintConvert;
import cn.iocoder.yudao.module.fengdong.smartelderly.dal.dataobject.complaint.ComplaintDO;
import cn.iocoder.yudao.module.fengdong.smartelderly.service.complaint.ComplaintService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Tag(name = "用户 APP - 投诉管理")
@RestController
@RequestMapping("/fengdong.smartelderly/complaint")
@Validated
public class AppComplaintController {

    @Resource
    private ComplaintService complaintService;

    @PostMapping("/create")
    @Operation(summary = "创建投诉管理")
    public CommonResult<Long> createComplaint(@Valid @RequestBody ComplaintCreateReqVO createReqVO) {
        return success(complaintService.createComplaint(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新投诉管理")
    public CommonResult<Boolean> updateComplaint(@Valid @RequestBody ComplaintUpdateReqVO updateReqVO) {
        complaintService.updateComplaint(updateReqVO);
        return success(true);
    }

    @PutMapping("/updatedispose")
    @Operation(summary = "处理反馈")
    public CommonResult<Boolean> updatedispose(@Valid @RequestBody ComplaintUpdatedisposeReqVO updateReqVO) {
        complaintService.updatedispose(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除投诉管理")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteComplaint(@RequestParam("id") Long id) {
        complaintService.deleteComplaint(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得投诉管理")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<ComplaintRespVO> getComplaint(@RequestParam("id") Long id) {
        ComplaintDO complaint = complaintService.getComplaint(id);
        return success(ComplaintConvert.INSTANCE.convert(complaint));
    }

    @GetMapping("/list")
    @Operation(summary = "获得投诉管理列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<ComplaintRespVO>> getComplaintList(@RequestParam("ids") Collection<Long> ids) {
        List<ComplaintDO> list = complaintService.getComplaintList(ids);
        return success(ComplaintConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得投诉管理分页")
    public CommonResult<PageResult<ComplaintRespVO>> getComplaintPage(@Valid ComplaintPageReqVO pageVO) {
        PageResult<ComplaintDO> pageResult = complaintService.getComplaintPage(pageVO);
        return success(ComplaintConvert.INSTANCE.convertPage(pageResult));
    }
}
